// router.js 样式模板
function getRouter(appRouter){
  let routerModule = {}
  let router = []
  console.log(appRouter)
  for (var i = 0 ; i < appRouter.length;  i++) {
    var name = appRouter[i];
    console.log(name)
    routerModule = `{
        path: '/${name}',
        name: '${name}',
        title: '${name}',
        component: Main,
        children: [
            {
                path: '${name}',
                icon: 'icon-iviewshezhi',
                name: '${name}',
                title: '${name}',
                component: () => import('@/views/${name}/index.vue')
            },
        ]
    }`
    router.push(routerModule)
  }
  return router.toString();
}

module.exports = {
  routerTemplate: appRouter => {
    return `import Main from '@/views/Main.vue'

// 不作为Main组件的子页面展示的页面单独写，如下
export const loginRouter = {
    path: '/login',
    name: 'login',
    meta: {
        title: 'Login - 登录'
    },
    component: () => import('@/views/Login.vue')
}

export const page404 = {
    path: '/*',
    name: 'error-404',
    meta: {
        title: '404-页面不存在'
    },
    component: () => import('@/components/error-page/404.vue')
}

export const page403 = {
    path: '/403',
    meta: {
        title: '403-权限不足'
    },
    name: 'error-403',
    component: () => import('@//components/error-page/403.vue')
}

export const page500 = {
    path: '/500',
    meta: {
        title: '500-服务端错误'
    },
    name: 'error-500',
    component: () => import('@/components/error-page/500.vue')
}


// 作为Main组件的子页面展示但是不在左侧菜单显示的路由写在otherRouter里
export const otherRouter = {
    path: '/',
    name: 'otherRouter',
    redirect: '/home',
    component: Main,
    children: [
        {
          path: 'home',
          title: '首页',
          name: 'home_index',
          component: () => import('@/components/home/home.vue')
        },
    ]
}

// 作为Main组件的子页面展示并且在左侧菜单显示的路由写在appRouter里
// 根据views里的文件会自动生成一个相应主路由，如一个模块有多个路由需自行填写
export const appRouter =[${getRouter(appRouter)}]

// 所有上面定义的路由都要写在下面的routers里
export const routers = [
    loginRouter,
    otherRouter,
    ...appRouter,
    page500,
    page403,
    page404,
]

`
  },
  entryTemplate: `import Main from './main.vue'
export default Main`
}

